
// 滚动分页需要 loading finished 遍历的list onload事件  api
import { reactive, ref } from 'vue'
export default function usePagePaging(api, data) {
    let apiData = reactive(data)
    let loading = ref(false);
    let finished = ref(false);
    let list = ref([]);

    let onLoad = async () => {
        let res = await api(apiData);
        let maxPage = Math.ceil(res.count / apiData.limit);
        if (apiData.page <= maxPage) {
            apiData.page++
        } else {
            finished.value = true
        }

        if (res.list) {
            list.value.push(...res.list);
        }
        loading.value = false;
    }
    return {
        loading,
        finished,
        onLoad,
        list
    }
}